function ti = dellayer(ti, l)
% transimg::dellayer  - remove (a) layer(s) of an image

% global variables for storage
global tiobj ...
       tiobjlup;
   
% check arguments
lup = find(tiobjlup == ti.L);
if numel(lup) ~= 1
    error( ...
        'transimg:ObjectRemoved', ...
        'Object removed from global storage.' ...
    );
end
if nargin < 2 || ...
   ~isa(l, 'double') || ...
    any(isinf(l(:)) | isnan(l(:)) | l(:) < 1)
    error( ...
        'transimg:InvalidCall', ...
        'Invalid call to transimg::addlayer.' ...
    );
end
l(l > numel(tiobj(lup).Layer)) = [];

% reset IsRendered flag
tiobj(lup).IsRendered = false;

% del layer
tiobj(lup).Layer(unique(round(l))) = [];
